//utf-8
//点击新增按钮 事件跳转至 新增页面

//修改 事件
var dialogUpdate;
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	var raiseStatus = iframe.iframeObj["table"].getSelectedObjs("raiseStatus");
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}
	var dialogStruct={
			'display':contextRootPath+'/tCMmRaisePlan/prepareExecute/toUpdate?id='+v_ids,
			'width':1200,
			'height':600,
			'title':'修改',
			'isIframe':'false',
			'buttons':[
             {'text':'提交','action':doUpdateFrom,'isClose':true},
			 {'text':'关闭','action':removeAttr,'isClose':true}
			]
		};
		
    dialogUpdate = jyDialog(dialogStruct);
    dialogUpdate.open();
}




//修改页面 的 保存操作
function doUpdateFrom(dialogUpdate){
	//序列化 新增页面的form表单数据
	var params=$("#updateNewsFormData").serialize();
	var url=contextRootPath+'/tCMmRaisePlan/updateTCMmRaisePlan';
	var raiseStatus = $("#dtoraiseStatus").val();
	var costCode = $("#costCode").val();
	var merchantPeriod = $("#dtomerchantPeriod").val();
	if(raiseStatus==""||null==raiseStatus){
		alert("募集状态不能为空！");
		return ;
	}
	
	if(merchantPeriod==""||null==merchantPeriod){
		alert("商户兑付期限不能为空！");
		return ;
	}
	
	if(costCode==""||null==costCode){
		alert("费用编码不能为空！");
		return ;
	}
	
	isCostCode(costCode,url,params);
}

function isCostCode(costCode,url,params){
	var urlCost =contextRootPath + "/tCMmCostParam/queryListTCMmCostParam?costCode=" + costCode;
	var paramsCost;
	jyAjax(
			urlCost,
			paramsCost,
			function(msg){
				var msgData = msg.data;
 	         	var costCodeDate;
 	         	if(null==msgData){
 	         		costCodeDate=null;
 	         	}else{
 	         		costCodeDate = msgData.length;
 	         	}
	     		if(costCodeDate>=1){
	     			updateDate(url,params);
	        	}else {
	        		alert("费用编码对应的费用参数不存在，请配置！");	
	        		return;
	        	}
	  	});
}

function updateDate(url,params){
	jyAjax(
		url,
		params,
		function(msg){
			//保存成功后，执行查询页面查询方法
			alert(msg.msg);
        	var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){	        		
        		queryData();
        	}
  	});
}

function removeAttr(){
	$('input').removeAttr("disabled");
	$('input').removeAttr("readonly");
	
}

//导出募集计划
function exportRaisePlan(){
	var startTimeDate = $("input[name=startTimeDate]").val();
	var endTimeDate = $("input[name=endTimeDate]").val();
	var planId = $("input[name=planId]").val();
	var planName = $("input[name=planName]").val();
	var raiseStatus = $("select[name=raiseStatus]").val();
	var costCode = $("input[name=costCode]").val();
	
	var url = contextRootPath+'/raisePlanCtrl/exportRaisePlan?planId=' + planId + '&planName=' + encodeURI(encodeURI(planName)) +'&raiseStatus=' + raiseStatus + '&startTimeDate=' + startTimeDate + '&endTimeDate=' + endTimeDate + '&costCode=' + costCode;
	window.location = url;
}

function updateRaisePlanItemSum(){
	var params='';
	var url=contextRootPath+'/raisePlanCtrl/updateRaisePlanItemSum';
	
	//通过ajax保存
	jyAjax(
		url,
		params,
		function(msg){
			//保存成功后，执行查询页面查询方法
        	var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		queryData();
        	}
  	});
}